package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("userShopController")
@RequestMapping("user/shop")
public class ShopController {

    public static final String KEY= "shop_status";

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("获取店铺营业状态")
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get(KEY);
        if (shopStatus == null) {
            // 如果缓存中没有数据，则从数据库中查询
            shopStatus = 1;
            redisTemplate.opsForValue().set(KEY, shopStatus);
        }
        log.info("获取店铺营业状态：{}", shopStatus == 1 ? "营业中" : "打样中");
        return Result.success(shopStatus);
    }
}
